package com.hqyj.controller;

import com.hqyj.pojo.Goods;
import com.hqyj.pojo.Reserve;
import com.hqyj.service.ReserveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@RequestMapping("/Reserve")
@Controller
public class ReserveController {
    @Autowired
    ReserveService reserveService;

    //添加到我的预定里面
    @RequestMapping("/tableReserve")
    public String tableReserve(){

        return "table/tableReserveList";
    }
    @RequestMapping("/tableReserve1")
    public String tableReserve1(String userName,Model model){
        int userId = reserveService.selectUserIdByUserName(userName);
        model.addAttribute("userId",userId);
        return "table/tableReserveList";
    }
    @RequestMapping("/tableReserveListAjax")
    @ResponseBody
    public HashMap<String,Object> query(Goods goods, HttpServletRequest request){
        System.out.println("大哥别搞我啊"+reserveService.select(goods,request));
        return reserveService.select(goods,request);
    }

    @RequestMapping("/reviewTableListAjax")
    @ResponseBody
    public HashMap<String,Object> update(Goods goods, HttpServletRequest request){
        System.out.println("大哥别搞我啊"+reserveService.select(goods,request));
        return reserveService.select(goods,request);
    }

    @RequestMapping("/ReserveUpdateAjax")
    @ResponseBody
    public HashMap<String,Object> ReserveUpdateAjax(Reserve reserve){

        return reserveService.update(reserve);
    }

    @RequestMapping("/updateViewStateAjax")
    @ResponseBody
    public HashMap<String,Object> updateViewStateAjax(Goods goods){

        return reserveService.updateViewState(goods);
    }

    @RequestMapping("/updateViewStateAjax1")
    @ResponseBody
    public HashMap<String,Object> updateViewStateAjax1(Goods goods){

        return reserveService.updateViewState1(goods);
    }

    //访问edit页面的方法
    @RequestMapping("/edit")
    public String edit(Integer tId,Integer userId, Model model){
        System.out.println("===="+tId+"===="+userId);
        Reserve a = reserveService.selectById(tId,userId);
        System.out.println("=============你是什么意思？=========="+a);
        int b = reserveService.selectNumber(a);
        model.addAttribute("a",a);
        model.addAttribute("number",b);
        return "table/edit";
    }

    //删除订单
    @RequestMapping("/deleteReserveListAjax")
    @ResponseBody
    public HashMap<String,Object> deleteReserveListAjax(Reserve reserve){

        return reserveService.deleteReserveBytId(reserve);
    }

    //占据座位
    @RequestMapping("/haveSeatAjax")
    @ResponseBody
    public HashMap<String,Object> haveSeatAjax(Reserve reserve){

        return reserveService.updateTableState(reserve);
    }

    //管理员审核！

}
